require 'rho/rhocontroller'
require 'helpers/browser_helper'

class HomeController < Rho::RhoController
  include BrowserHelper

  def popup_callback
    id = @params['button_id']
    title = @params['button_title']
    puts "popup_callback: id: '#{id}', title: '#{title}'"
    
    if title.downcase() == 'yes'
			puts "++++---- quitting application"
			System.exit
		end
		
  end
  
  def callback_alert
    puts "+++--- callback_alert"
    
    Alert.show_popup( :title => "Quit Application", :message => "Do you want to quit the application?", :icon => :question,
      :buttons => ["Yes", "No"], :callback => url_for(:action => :popup_callback) )   
  end 

  #GET /Home
  def index
    @homes = Home.find(:all)
    render :action => :index, :back => 'callback:' + url_for(:action => :callback_alert)
  end

  # GET /Home/{1}
  def show
    @home = Home.find(@params['id'])
    if @home
      render :action => :show
    else
      redirect :action => :index
    end
  end

  # GET /Home/new
  def new
    @home = Home.new
    render :action => :new
  end

  # GET /Home/{1}/edit
  def edit
    @home = Home.find(@params['id'])
    if @home
      render :action => :edit
    else
      redirect :action => :index
    end
  end

  # POST /Home/create
  def create
    @home = Home.create(@params['home'])
    redirect :action => :index
  end

  # POST /Home/{1}/update
  def update
    @home = Home.find(@params['id'])
    @home.update_attributes(@params['home']) if @home
    redirect :action => :index
  end

  # POST /Home/{1}/delete
  def delete
    @home = Home.find(@params['id'])
    @home.destroy if @home
    redirect :action => :index
  end
end
